package com.irdstudio.bsp.console.api.rest;

import com.irdstudio.bsp.console.service.facade.SSrvsCronConfService;
import com.irdstudio.bsp.console.service.vo.SSrvsCronConfVO;
import com.irdstudio.sdk.beans.core.vo.ResponseData;
import com.irdstudio.sdk.ssm.web.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class SSrvsCronConfController extends AbstractController  {
	
	@Autowired
	@Qualifier("sSrvsCronConfService")
	private SSrvsCronConfService sSrvsCronConfService;

	
	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/confs", method=RequestMethod.POST)
	public @ResponseBody ResponseData<List<SSrvsCronConfVO>> querySSrvsCronConfAll(SSrvsCronConfVO vo) {
		List<SSrvsCronConfVO> outputVo = sSrvsCronConfService.queryAllOwner(vo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf/{jobCode}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<SSrvsCronConfVO> queryByPk(@PathVariable("jobCode") String jobCode) {		
		SSrvsCronConfVO inVo = new SSrvsCronConfVO();
				inVo.setJobCode(jobCode);
		SSrvsCronConfVO outputVo = sSrvsCronConfService.queryByPk(inVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键删除信息
	 * @param sSrvsCronConf
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody SSrvsCronConfVO inSSrvsCronConfVo) {		
		int outputVo = sSrvsCronConfService.deleteByPk(inSSrvsCronConfVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 根据主键更新信息
	 * @param inSSrvsCronConfVo
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody SSrvsCronConfVO inSSrvsCronConfVo) {		
		int outputVo = sSrvsCronConfService.updateByPk(inSSrvsCronConfVo);
		return getResponseData(outputVo);
		
	}
	
	/**
	 * 新增数据
	 * @param inSSrvsCronConfVo
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertSSrvsCronConf(@RequestBody SSrvsCronConfVO inSSrvsCronConfVo) {
		int outputVo = sSrvsCronConfService.insertSSrvsCronConf(inSSrvsCronConfVo);
		return getResponseData(outputVo);
		
	}

	/**
	 * 手工发起
	 * @param inSSrvsCronConfVo
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf/do/start", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Boolean> startTask(@RequestBody SSrvsCronConfVO inSSrvsCronConfVo) {
		ResponseData<Boolean> data = null;
		if(sSrvsCronConfService.startTask(inSSrvsCronConfVo)){
			data = getResponseData(true);
			data.setMessage("手工发起成功！");
		}else{
			data = getResponseData(false);
			data.setMessage("手工发起失败！");
		}
		return data;
	}

	/**
	 * 禁用
	 * @param inSSrvsCronConfVo
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf/do/false", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Boolean> doDisable(@RequestBody SSrvsCronConfVO inSSrvsCronConfVo) {
		ResponseData<Boolean> data = null;
		if(sSrvsCronConfService.doDisable(inSSrvsCronConfVo)){
			data = getResponseData(true);
			data.setMessage("定时任务已禁用！");
		}else{
			data = getResponseData(false);
			data.setMessage("定时任务禁用失败！");
		}
		return data;
	}

	/**
	 * 启用
	 * @param inSSrvsCronConfVo
	 * @return
	 */
	@RequestMapping(value="/s/srvs/cron/conf/do/initial", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Boolean> doInitial(@RequestBody SSrvsCronConfVO inSSrvsCronConfVo) {
		ResponseData<Boolean> data = null;
		if(sSrvsCronConfService.doInitial(inSSrvsCronConfVo)){
			data = getResponseData(true);
			data.setMessage("定时任务启用成功！");
		}else{
			data = getResponseData(false);
			data.setMessage("定时任务启用失败！");
		}
		return data;
	}

}
